# -*- codeing = utf-8 -*-
# @Time : 2021/2/26 20:24
# @Atuthor: 朱朱
# @File: 124面向对象练习1.py
# @Software: PyCharm
""
"""
定义一个类,传入二个坐标,计算出这二个坐标组成的矩形的面积
给出一个坐标,验证这个坐标是否在矩形之内
"""
class Point(object):
    def __init__(self, x:int, y:int):
        self.x = x
        self.y =y

class Rectangle(object):
    def __init__(self, top_left:Point, bottom_right:Point):
        self.top_left = top_left
        self.bottom_right = bottom_right

    def get_area(self):
        length = abs(self.bottom_right.x - self.top_left.x)
        width = abs(self.top_left.y-self.bottom_right.y)
        return length*width

    def is_inside(self, point):
        return self.bottom_right.x>=point.x >=self.top_left.x and self.top_left.y>=point.y>=self.bottom_right.y

p1 = Point(4,20)
p2 = Point(30,8)

r = Rectangle(p1,p2)
print(r.get_area())
print('--------------------')

p = Point(20,30)
print(r.is_inside(p)) # false

x = Point(20,20)
print(r.is_inside(x)) # true
